package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.springframework.boot.autoconfigure.web.WebProperties;

import java.io.IOException;
//@WebFilter(urlPatterns = "/*")//拦截所以请求
public class DemoFilter implements Filter {

    @Override//初始化，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init初始化方法执行了");
    }

    @Override//拦截请求后调用，调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Demo拦截到了请求...放行前逻辑");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);

        System.out.println("Demo拦截到了请求...放行后逻辑");
    }

    @Override//销毁方法，只调用一次
    public void destroy() {
        System.out.println("init销毁方法执行了");
    }
}
